# -*- coding: utf-8 -*-
# @Author  : User1396529
# @Date    : 2023-12-22
# @Version : 0.1.0

# In[1]:

# 导入工具包

import random
import simpy
import pyforest
from BankRenegeSimulator import *
pd.set_option('display.max_rows', 10)

# In[2]:

# 设置仿真参数

RANDOM_SEED = 42           # 随机种子
NEW_CUSTOMERS = 600        # 顾客总人数
INTERVAL_CUSTOMERS = 10.0  # 大约每 n 分钟生成一名顾客
MIN_PATIENCE = 1           # 顾客的最小耐心时间
MAX_PATIENCE = 10          # 顾客的最大耐心时间
NUM_COUNTER = 1            # 银行柜台数
TIME_IN_BANK = 10.0        # 顾客滞留在银行里的时间
VIP_SCALE = 0.1            # 顾客中 VIP 的比例

# In[3]:

# 实例化仿真环境和仿真器

random.seed(RANDOM_SEED)
env = simpy.Environment()
simBank = BankSimulator(
    env, 
    NEW_CUSTOMERS,
    NUM_COUNTER,
    INTERVAL_CUSTOMERS,
    TIME_IN_BANK,
    MAX_PATIENCE,
    MIN_PATIENCE,
    vip_rate=VIP_SCALE)

# In[4]:

env.run()

# In[5]:

result = simBank.result()

# In[6]:

result.plot_info(dpi=300)

# In[7]:

unreneged_custumor = result.wait_time_df[
    result.wait_time_df['is_reneged'] == False
] # 提取没有中途跑路的顾客
all_customer = result.wait_time_df
all_customer

# In[8]:

fig, ax = plt.subplots(dpi=300)
sns.histplot(
    unreneged_custumor['wait_time'], 
    bins=10,
    kde=True,
    ax=ax, 
    label='waiting time (unreneged)' )
ax.legend()
ax.set_xlabel('等待时间')
ax.set_ylabel('客户数量')
ax.set_xlim(0, MAX_PATIENCE)
fig.suptitle('未退出客户的等待时间分布')